﻿using System.Data;
using System.Data.SqlClient;

namespace Adams.Web.Data
{
    public static class Pages
    {
        public static Models.Pages.Index.PageLoad PageLoad(string url)
        {
            var data = new Models.Pages.Index.PageLoad();
            data.Page = new Shared.Entities.Pages.Page();

            using (SqlDataReader dr = DB.RunDataReader(@"
SELECT P.*
FROM Pages.Pages P
WHERE P.Url = @Url
", CommandType.Text,
    DB.CreateParameter("@Url", url)))
            {
                if (dr.HasRows)
                {
                    dr.Read();
                    data.Page.ID = dr["PageID"].DbInt();
                    data.Page.Title = dr["Title"].DbString();
                    data.Page.Url = dr["Url"].DbString();
                    data.Page.Content = dr["Content"].DbString();
                }

                return data;
            }
        }
    }
}
